var interval
function refresh(params, title, url, dyUrl, yaxis, unit) {
    $.request(url, params, function (content) {
        var seriesOptions = [];
        $(content).each(function (i, node) {
            seriesOptions[i] = {
                name: node.name,
                type: 'line',
                data: eval("(" + node.data + ")")
            };
        });
        if (interval) {
            clearInterval(interval);
        }
        $('#container').highcharts({
            title: {
                text: (params.hostPort ? params.hostPort : (params.service + " " + params.method)) + " " + title,
                x: -20 //center
            },
            chart: {
                events: {
                    load: function () {
                        var map = {};
                        for (var i in this.series) {
                            map[this.series[i].name] = i;
                        }
                        var series = this.series[0];
                        var $series = this.series;
                        interval = setInterval(function () {
                            var _time = series.data[series.data.length - 1];
                            var time = _time.category;
                            $.request(dyUrl + "?time=" + time, params, function (dy_content) {
                                if (dy_content[0].name != undefined) {
                                    $(dy_content).each(function (i, node) {
                                        var x = node.time;
                                        var y = parseFloat(node.value);
                                        $series[map[node.name]].addPoint([x, y], true, true);
                                    });
                                }
                            });
                        }, 20000);
                    }
                }
            },
            xAxis: {
                labels: {
                    formatter: function () {
                        return Highcharts.dateFormat("%m-%d %H:%M", this.value);
                    }
                },
                type: 'datetime',
                dateTimeLabelFormats: {
                    day: '%m-%d %H:%M'
                },
                tickInterval: 300000
            },
            yAxis: {
                title: {
                    text: yaxis
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080',
                }]
            },
            plotOptions: {
                series: {
                    marker: {
                        enabled: true
                    }
                }
            },
            credits: {
                enabled: false // 禁用版权信息
            },
            tooltip: {
                crosshairs: true,
                valueDecimals: 2,
                formatter: function () {
                    var s = '<b>' + Highcharts.dateFormat("%m-%d %H:%M", this.x) + '</b>';
                    $.each(this.points, function () {
                        s += '<br/>' + this.series.name + ': ' +
                            this.y.toFixed(2) + unit;
                    });
                    return s;
                },
                shared: true
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle',
                borderWidth: 0
            },
            series: seriesOptions
        });
    });
}
Highcharts.setOptions({global: {useUTC: false}});